home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cp1.zip / SEARCH1.C < prev    next >
C/C++ Source or Header  |  1993-05-15  |  5KB  |  112 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville MI
  3. Date: 05-10-93 (00:00)             Number: 22
  4. From: BRAD GREEP                   Refer#: NONE
  5.   To: MARK CORGAN                   Recvd: NO  
  6. Subj: Re: SEARCH FUNCTION            Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8.  On 05-09-93 Mark Corgan wrote...
  9.  
  10.  MC> I will post my tree and search functions in the next message...
  11.  
  12.         Looking forward to it.
  13.  
  14.  MC>  BG> The advantage to using a text file is that you can format it any way y
  15. ou
  16.  MC>  BG> want and then redirect it to the printer or text editor if you need to
  17. .
  18.  MC>
  19.  MC> That is exactly why I am maintaining the two different files.
  20.  
  21.         What I did in my program was to maintain one file and then
  22.         "print" it to a file when I wanted it.  There was less to
  23.         maintain and I could change the output format if I wanted.
  24.         I set the mode to "wb" and it would just overwrite the
  25.         existing file.
  26.  
  27.  MC> I would be interested in SearchIndex. Is it small enough to post? As for B-
  28.  
  29.  MC> trees, I am just beginning to explore them. If I have any
  30.  MC> exciting revelations, I will be sure to post them.
  31.  
  32. ___------------------8<-------------------------
  33. #include <stdio.h>
  34. /*
  35. Disclaimer:
  36.         This function is released to the public domain by the author,
  37.         John Greep.  The author cannot be held responsible for any
  38.         loss or damages resulting from the use of this function, whether
  39.         actual or inferred.
  40. */
  41. int SearchIndex (name,index,size,isize,pos,num,off,istore,store,search)
  42.  
  43. char    *name,   /* Master File Name                                    */
  44.         *index;  /* Index File Name                                     */
  45. int     size,    /* Master File Record Size                             */
  46.         isize,   /* Index File Record Size                              */
  47.         pos,     /* Record Position to Search                           */
  48.         num;     /* Record number within file to begin search           */
  49. long    *off;    /* Address of Index Record variable holding location   */
  50. char    *istore, /* Pointer to Index Record storage area                */
  51.         *store,  /* Pointer to Master Record storage area               */
  52.         *search; /* Pointer to Search string                            */
  53. {
  54.         char *temp, *stemp;
  55.         FILE *fp, *ip;
  56.  
  57.         if ((fp = fopen(name,"rb"))==NULL) return 0;
  58.         if ((ip = fopen(index,"rb"))==NULL) return 0;
  59.         fseek (ip, (num - 1) * isize, SEEK_SET);
  60.         while (fread (istore, isize, 1, ip))
  61.         {
  62.                 fseek (fp, *off, SEEK_SET);
  63.                 fread (store,size,1,fp);
  64.                 stemp = store + pos -1;
  65.                 while (*stemp && *search)
  66.                 {
  67.                         temp = search;
  68.                         while ((*stemp|32)==(*temp|32)&&*temp)
  69.                         {
  70.                                 stemp++;
  71.                                 temp++;
  72.                         }
  73.                         if (!*temp)
  74.                         {
  75.                                 temp--;
  76.                                 stemp--;
  77.  
  78.                                 if ((*stemp|32)==(*temp|32))
  79.                                 {
  80.                                         fclose (fp);
  81.                                         fclose (ip);
  82.                                         return num;
  83.                                 }
  84.                         }
  85.                         if ((*stemp|32) != (*search|32))
  86.                                 stemp++;
  87.                 }
  88.                 num++;
  89.         }
  90.         fclose (fp);
  91.         fclose (ip);
  92.         return 0;
  93. }
  94. -----------------------8<-------------------------
  95.  
  96.         Not much different than the last function.  It instead steps
  97.         through the index and references the master file from there.
  98.  
  99.  MC>  BG> Also, the size of your index can be just over 2000 records before you
  100.  MC>  BG> hit 64K.  That's at 31 bytes per record.
  101.  MC>
  102.  MC> Yes. That is true. But I was speaking about static arrays.
  103.  MC> Does this still hold true? I genereated the "DGROUP segment
  104.  MC> exceeded" error when statically allocating more than 350
  105.  MC> arrays. ???
  106.  
  107.         I'm not sure about static arrays.  I suppose it would--- TBBS v2.1/NM
  108.  * Origin: Autodesk Global Village (1:125/289)
  109. SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
  110. SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 261/1023
  111. SEEN-BY: 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20
  112.